package model;

import java.awt.Font;
import java.util.Iterator;
import java.util.Vector;

/**
 * Team EBE
 * 
 * ClassImpl.java represents a model of a UML class, maintains the 
 * class' name, attributes, and operations
 *
 */
public class ClassImpl {
	private String name;
	private int oX, oY, width, height, numAts, numOps;
	private Vector<AttributeImpl> attributes;
	private Vector<OperationImpl> operations;
	private Vector<AnchorPoint> anchorPoints;

	public ClassImpl() {
		
		this.name = null;
		
		initLists();
	}

	public ClassImpl(String nameIn) {
		this.name = nameIn;
		this.numAts = this.numOps = this.oX = this.oY = 0;
		this.width = this.height = 200;
		initLists();
	}
	
	public ClassImpl (int oXIn, int oYIn){
		this.name = "New Class";
		this.oX = oXIn;
		this.oY = oYIn;
		this.width = this.height = 200;
		initLists();
	}

	private void initLists() {
		attributes = new Vector<AttributeImpl>();
		operations = new Vector<OperationImpl>();
		anchorPoints = new Vector<AnchorPoint>(8);
		initAnchors();
		updateAnchors();
		new Vector<AnchorPoint>();
	}
	
	public void initAnchors(){
		for(int i = 0; i < 8; i++){
			anchorPoints.add(new AnchorPoint(0,0,this.name));
		}
	}
	
	public AnchorPoint anchorAt(int i){
		return anchorPoints.elementAt(i);
	}
	
	public void updateAnchors(){
		anchorPoints.elementAt(0).x = oX;
		anchorPoints.elementAt(0).y = oY;
		anchorPoints.elementAt(1).x = oX + (width / 2);
		anchorPoints.elementAt(1).y = oY;
		anchorPoints.elementAt(2).x = oX + width;
		anchorPoints.elementAt(2).y = oY;
		anchorPoints.elementAt(3).x = oX + width;
		anchorPoints.elementAt(3).y = oY +(height / 2);
		anchorPoints.elementAt(4).x = oX + width;
		anchorPoints.elementAt(4).y = oY +height;
		anchorPoints.elementAt(5).x = oX + (width / 2);
		anchorPoints.elementAt(5).y = oY + height;
		anchorPoints.elementAt(6).x = oX;
		anchorPoints.elementAt(6).y = oY + height;
		anchorPoints.elementAt(7).x = oX;
		anchorPoints.elementAt(7).y = oY + (height / 2);
	}

	public void addAttribute(String nameIn, String typeIn, char visIn) {
		AttributeImpl atIn = new AttributeImpl(nameIn, typeIn, visIn);
		attributes.add(atIn);
		++numAts;
	}

	public void addOperation(String nameIn, String typeIn, char visIn) {
		OperationImpl opIn = new OperationImpl(nameIn, typeIn, visIn);
		operations.add(opIn);
		++numOps;
	}
	
	public void updateSize(){
		//this.setHeight(12 + (22 * (attributes.size() + operations.size())));
	}
	
	public Vector<OperationImpl> getOperations(){
		return operations;
	}
	
	public Vector<AttributeImpl> getAttributes(){
		return attributes;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getoX() {
		return oX;
	}

	public void setoX(int oX) {
		this.oX = oX;
		updateAnchors();
	}

	public int getoY() {
		return oY;
	}

	public void setoY(int oY) {
		this.oY = oY;
		updateAnchors();
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int sizeX) {
		this.width = sizeX;
		updateAnchors();
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int sizeY) {
		this.height = sizeY;
		updateAnchors();
	}
	
	public void setAttributes(Vector<AttributeImpl> attributesIn){
		this.attributes = attributesIn;
	}
	
	public void setOperations(Vector<OperationImpl> operationsIn){
		this.operations = operationsIn;
	}
	
	public Vector<AnchorPoint> getAnchorPoints(){
		return anchorPoints;
	}
}
